package cn.sunline.shengpizi;

import java.io.UnsupportedEncodingException;

public class MainTester {

    /**
     * 判断字符串里是否有生僻字
     */
    public static Boolean isLessUseWord(String org) throws UnsupportedEncodingException {
        return !org.equals(new String(org.getBytes("gb18030"),"gb2312"));
    }


    public static void main(String[] args) throws UnsupportedEncodingException {
        String split="---------------------------------------------------------";
        //字符串转unicode
        System.out.println(split);
        String unioncode = UnicodeUtil.StringToUnicode("王䬅");
        System.out.println(unioncode);

        //判断字符串里是否有生僻字
        System.out.println(split);
        System.out.println(isLessUseWord("王䬅"));
        System.out.println(isLessUseWord("王"));

        //判断字符串长度
        System.out.println(split);
        byte [] bytes_gbk = "张䬅".getBytes("gbk");
        byte [] bytes_utf8 = "张䬅".getBytes("utf-8");
        byte [] bytes_unicode = "张䬅".getBytes("unicode");
        byte [] bytes_gbk1 = "张三".getBytes("gbk");
        byte [] bytes_utf81 = "张三".getBytes("utf-8");
        byte [] bytes_unicode1 = "张三".getBytes("unicode");
        System.out.println(bytes_gbk.length);
        System.out.println(bytes_utf8.length);
        System.out.println(bytes_unicode.length);
        System.out.println(bytes_gbk1.length);
        System.out.println(bytes_utf81.length);
        System.out.println(bytes_unicode1.length);
        String str_gbk = new String(bytes_gbk,"gbk");
        String str_utf8 = new String(bytes_utf8,"utf-8");
        String str_unicode = new String(bytes_unicode,"unicode");
        System.out.println(str_gbk);//无法还原，因为生僻字里没有收录生僻字
        System.out.println(str_utf8);
        System.out.println(str_unicode);

        //将生僻字转unicode
        System.out.println(split);
        String s = "张䬅";
        String str_unicode1 = UnicodeUtil.StringToUnicode(s);
        System.out.println(str_unicode1);
        //将unicode转回
        System.out.println(UnicodeUtil.UnicodeToString(str_unicode1));
    }
}
